package day14.example;

import org.junit.Test;

import java.sql.*;

public class JDBCText {
//    @Test
//
//    public void textAddAccount() {
//        try {
//            Class.forName("com.mysql.cj.jdbc.Driver");
//            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/text1", "root", "root");
//            String sql = "insert into account value(1,'Tom',1000)";
//            Statement statement = connection.createStatement();
//            int result = statement.executeUpdate(sql);
//            System.out.println(result);
//            statement.close();
//            connection.close();
//        } catch (ClassNotFoundException e) {
//            System.out.println(e);
//        } catch (SQLException ex) {
//            System.out.println(ex);
//        }
//    }

//    @Test
//    public void testDeleteAccount() {
//        try {
//            Class.forName("com.mysql.cj.jdbc.Driver");
//            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/text1", "root", "root");
//            String sql = "delete from account where id=1";
//            Statement statement = connection.createStatement();
//            int result = statement.executeUpdate(sql);
//            System.out.println(result);
//            statement.close();
//            connection.close();
//        } catch (ClassNotFoundException e) {
//            System.out.println(e);
//        } catch (SQLException ex) {
//            System.out.println(ex);
//        }
//    }

    @Test
    public void testDropTable() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/text1", "root", "root");
            String sql = "drop table account";
            Statement statement = connection.createStatement();
            int result = statement.executeUpdate(sql);
            System.out.println(result);
            statement.close();
            connection.close();
        } catch (ClassNotFoundException e) {
            System.out.println(e);
        } catch (SQLException ex) {
            System.out.println(ex);
        }
    }
//    @Test
//    public void testQueryAccount() {
//        try {
//            Class.forName("com.mysql.cj.jdbc.Driver");
//            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/text1", "root", "root");
//            String sql = "select * from account";
//            Statement statement = connection.createStatement();
//            ResultSet resultSet = statement.executeQuery(sql);
//            while (resultSet.next()) {
//                int id = resultSet.getInt("id");
//                String name = resultSet.getString("name");
//                int balance = resultSet.getInt("balance");
//                System.out.println(id + " " + name + " " + balance);
//            }
//            System.out.println(resultSet);
//            statement.close();
//            connection.close();
//        } catch (ClassNotFoundException e) {
//            throw new RuntimeException(e);
//        } catch (SQLException ex) {
//            throw new RuntimeException(ex);
//        }
//
//    }
}
